#!/bin/bash
set -e

if [ -n "$(git status --porcelain --untracked-files=no)" ]; then
    DIRTY="-dirty"
fi

VERSION=$(cat $(dirname $0)/../version)
GIT_TAG=$(git tag -l --contains HEAD | head -n 1)

if [[ -z "$DIRTY" && -n "$GIT_TAG" ]]; then
    VERSION=$GIT_TAG
    IMAGE_TAG_PREFIX=$GIT_TAG
else
    IMAGE_TAG_PREFIX="$(git rev-parse --short HEAD)${DIRTY}"
fi

GITCOMMIT="$(git rev-parse HEAD)${DIRTY}"
BUILDDATE=$(date -u --rfc-3339=seconds)
BUILDDATE=${BUILDDATE// /T}
